//
//  TBCReadingViewCell.m
//  待定
//
//  Created by BoyaLee on 15/11/7.
//  Copyright © 2015年 BoyaLee. All rights reserved.
//

#import "TBCReadingViewCell.h"
#import "TBCReading.h"
#import "TBCReadingCollectionViewCell.h"

@interface TBCReadingViewCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation TBCReadingViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
    }
    
    return self;
    
}

- (void)initReadingCellViews {
    
    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake((WIDTH - 75) / 3, (HEIGHT - 64) * 0.2);
    flowLayout.minimumInteritemSpacing = 15;
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
    
    BaseCollectionView *collectionView = [[BaseCollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, (HEIGHT - 64) * 0.2) collectionViewLayout:flowLayout];
    //collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    [collectionView registerClass:[TBCReadingCollectionViewCell class] forCellWithReuseIdentifier:@"readingCollectionViewCell"];
    [self addSubview:collectionView];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 3;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellIdentifier = @"readingCollectionViewCell";
    
    TBCReadingCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    
    cell.reading = self.array[indexPath.item];
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    TBCReading *reading = self.array[indexPath.item];
    
    [self.delegate pushToController:reading.type];
    
}

- (void)setArray:(NSMutableArray *)array {
    
    _array = array;
    
    [self initReadingCellViews];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
